package com.mfl.controller;

import com.mfl.common.Result;
import com.mfl.pojo.vo.BannerVO;
import com.mfl.service.BannerService;
import com.mfl.utils.QiniuOSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/cky/common")
@Slf4j
public class CommonController {

    @Autowired
    private BannerService bannerService;

    /**
     * 文件上传 七牛云
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
        log.info("文件名：{}", file.getOriginalFilename());
        String uploadFileName = QiniuOSSUtil.uploadToQiniu(file);
        return Result.success("上传成功", uploadFileName);
    }

    /**
     * 获取轮播图列表
     * @return
     */
    @GetMapping("/getBannerList")
    public Result<List<BannerVO>> getBannerList(){
        log.info("获取轮播图列表");
        return Result.success("", bannerService.getBannerList());
    }
}
